home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / WPJV1N2.ZIP / HELLO.ZIP / HELLO.C next >
C/C++ Source or Header  |  1993-02-01  |  4KB  |  122 lines

  1. /*      Hello.C
  2.     By Pete Davis and Mike Wallace
  3.     Windows Programmer's Journal
  4.     Volume 1 Number 2
  5.     
  6. */
  7.  
  8. #include <windows.h>
  9. #include "hello.h"
  10.  
  11. BOOL InitInstance (HANDLE);
  12.  
  13. /* The main procedure. This is called by Windows when your program is run. */
  14. /* hCurrInst is the handle for the current instance of the program         */
  15. /* hPrevInst is teh handle for the last instance of the program to run     */
  16. /* CmdLine is a pointer to a string of whatever command line params came in*/
  17. /* nCmd is the specifies the applications appearance.                      */
  18.  
  19. int FAR PASCAL WinMain(HANDLE hCurrInst, HANDLE hPrevInst, LPSTR CmdLine, int nCmd) {
  20.  
  21. MSG             msg;                    /* Message                       */
  22. HWND    hWnd;                   /* Our Window Handle */
  23.  
  24.     if (!hPrevInst) {                       /* If no instance already exists, */
  25.         if (!InitInstance(hCurrInst))   /* try initializing instance      */
  26.         return FALSE;                           /* No dice, it failed             */
  27.     }
  28.     
  29.     hWnd=CreateWindow(      "Hello",                                /* Window Class                 */
  30.                         "Hello World Program",  /* Window caption               */
  31.                         WS_OVERLAPPEDWINDOW,    /* Overlapped style             */
  32.                         CW_USEDEFAULT,                  /* Use defaults for the */
  33.                         CW_USEDEFAULT,                  /* X & Y Positions and  */
  34.                         CW_USEDEFAULT,                  /* X & Y sizes                  */
  35.                         CW_USEDEFAULT,          
  36.                         NULL,                                   /* Parent Window                */
  37.                         NULL,
  38.                         hCurrInst,                              /* Instance                             */
  39.                         NULL);                                  /* Creation Params              */
  40.  
  41.     ShowWindow(hWnd, nCmd);
  42.     UpdateWindow(hWnd);
  43.     
  44.     while (GetMessage(&msg, NULL, 0, 0)) {
  45.         TranslateMessage(&msg);
  46.         DispatchMessage(&msg);
  47.     }
  48.     
  49.     return (msg.wParam);
  50. }
  51.  
  52.  
  53. BOOL InitInstance(HANDLE hInstance) {
  54.  
  55. WNDCLASS        wc;                             /* Window class structure */
  56.  
  57.     wc.lpszMenuName = "amenu";                /* Our Menu       */
  58.     wc.lpszClassName= "Hello";                      /* Used above in CreateWindow */
  59.     wc.hbrBackground= GetStockObject(WHITE_BRUSH);  /* White bkgrnd   */
  60.     wc.hInstance    = hInstance;
  61.     wc.style        = CS_VREDRAW | CS_HREDRAW;
  62.     wc.lpfnWndProc  = MainWndProc;          /* Name of proc to handle window */
  63.     wc.hCursor      = LoadCursor(NULL, IDC_ARROW);          /* Arrow Cursor */
  64.     wc.hIcon        = LoadIcon(NULL, IDI_APPLICATION);  /* Generic Icon */
  65.     wc.cbClsExtra   = 0;            /* no extras */
  66.     wc.cbWndExtra   = 0;            /* No Extras */
  67.     
  68.     return (RegisterClass(&wc)); /* Let's register that class */
  69. }
  70.  
  71. /* This is our main windows procedure. It receives messages in message, then,
  72. depending on what the message is, we react accordingly
  73. */
  74.  
  75. long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam) {
  76.  
  77.     switch(message) {
  78.     
  79.         /* WM_COMMAND may mean one of our menu items was selected */
  80.         case WM_COMMAND:
  81.         
  82.             /* Check for a menu item */
  83.             switch(wParam) {
  84.             
  85.                 /* Did the user select Hello? */
  86.                 case IDM_HELLO:
  87.                     /* Say Hello World */
  88.                     MessageBox(hWnd, "Hello World!", "Hello", MB_OK);
  89.                     
  90.                     /* Ok, that's all there is. */
  91.                     break;
  92.                 
  93.                 /* Oh, they wanna leave. Too bad. */    
  94.                 case IDM_QUIT:
  95.                     PostQuitMessage(0);
  96.                     break;
  97.                     
  98.                 /* We don't want it, so give it back to Windows */
  99.                 default: 
  100.                     return (DefWindowProc(hWnd, message, wParam, lParam));
  101.                     break;
  102.                 
  103.             }
  104.  
  105.             break;
  106.                     
  107.                 
  108.                 
  109.         /* Quit out of program when we receive a WM_DESTROY */
  110.         case WM_DESTROY:
  111.             PostQuitMessage(0);
  112.             break;
  113.             
  114.         /* Default case; We don't need it, so give it back to Windows */                
  115.         default:
  116.             return (DefWindowProc(hWnd, message, wParam, lParam));
  117.             break;
  118.     }
  119.                     
  120. }
  121.  
  122.